﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using IgnData;

namespace WpfIgnData
{
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private const int nt = 10;
        private const int tileSize = 256;
        BitmapImage img = new BitmapImage();

        //Referencias geograficas
        Point pxRefPoint = new Point();


        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            int x = int.Parse(txtX.Text);
            int y = int.Parse(txtY.Text);
            System.Drawing.Point utmPoint = new System.Drawing.Point(x, y);
            IgnMap map = MapFactory.GetMapByTileSize( new GeoCoord(x,y),nt);            
            mapImage.Source = loadBitmap(map.Bmp);
        }

        public static BitmapSource loadBitmap(System.Drawing.Bitmap source)
        {
            return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
        }

        private void mapImage_MouseMove(object sender, MouseEventArgs e)
        {
            pxRefPoint.X =  e.GetPosition((Image)sender).X;
            pxRefPoint.Y = e.GetPosition((Image)sender).Y;
            pxPos.Content = string.Format("(X, Y): ( {0}, {1})", pxRefPoint.X.ToString("0") , pxRefPoint.Y.ToString("0"));
        }
    }
}
